// import {React} form  'react'
import React, { useState } from "react";

import "./AddIntelligent_lighting.scss";
import "../../../static/font/iconfont.css";
import { AddBuildingMap } from "../AddBuildingMap/AddBuildingMap";
import http from "../../../utils/http";
import getLocalTime from "../../../utils/getLocalTime";

import {
    Form,
    Input,
    Button,
    Select,
    message,
    Modal,
    DatePicker,
    Upload,
} from "antd";
import { ExclamationCircleOutlined, InboxOutlined } from "@ant-design/icons";
// import ImgCrop from "antd-img-crop";

const { Option } = Select;
const { confirm } = Modal;

export const AddIntelligent_lighting = (props) => {
    console.log(props);
    const [bbform] = Form.useForm();
    const [Grform] = Form.useForm();
    const [Jbform] = Form.useForm();

    // 设备详情的新增数据
    const AddData = () => {
        // 获取页面上from表单的数据
        // let json1 = form.getFieldValue(true);
        let json = Jbform.getFieldsValue(true);
        let location = Grform.getFieldsValue(true).dinfLocation;
        console.log(json, location);
        if (
            json.ddetName != "" &&
            json.ddetNumber != "" &&
            json.ddetType != "" &&
            json.ddetFactorydate != "" &&
            json.dinfState != "" &&
            location.dinfLocation != ""
        ) {
            http({
                url: "/device/deviceAdd",
                method: "post",
                params: {
                    ddetName: json.ddetName,
                    ddetNumber: json.ddetNumber,
                    ddetType: json.ddetType,
                    dinfRuntime: json.ddetFactorydate,
                    dinfState: json.dinfState,
                    ddetFactory: json.factory,
                    ddetVersion: json.banben,
                    ddetStyle: json.style,
                    dinfLocation: location.dinfLocation,
                    adminId: 1,
                },
            }).then((res) => {
                console.log(res);
                if (res.code == 200) {
                    message.success("保存成功", [0.8]);
                    setTimeout(() => {
                        props.setaddIntelligent_lighting(false);
                    }, 1500);
                }
            });
        }
    };
    const layout = {
        labelCol: {
            span: 6,
        },
        wrapperCol: {
            span: 14,
        },
    };
    const tailLayout = {
        wrapperCol: {
            offset: 8,
            span: 16,
        },
    };
    //返回页面
    const backCar = () => {
        console.log(props);
        props.setaddIntelligent_lighting(false);
    };
    const quxiao = () => {
        confirm({
            icon: <ExclamationCircleOutlined />,
            content: "您确定离开此页面吗？",
            cancelText: "取消",
            okText: "确定",
            onOk() {
                //   console.log('OK');
                backCar();
            },
            onCancel() {
                console.log("Cancel");
            },
        });
    };
    // const onFinish = (values) => {
    //     console.log(values);
    // };
    // 上传图片
    const normFile = (e) => {
        console.log("Upload event:", e);

        if (Array.isArray(e)) {
            return e;
        }

        return e && e.fileList;
    };

    return (
        <div className="xinzeng">
            <div>
                <div className="tit1">
                    <div>
                        <div>
                            <div></div>
                            <div>智能荷储管理新增</div>
                        </div>
                    </div>
                    <div>
                        <span
                            className="iconfont icon-a-16guanbi"
                            onClick={backCar}
                        ></span>
                    </div>
                </div>
                <hr></hr>
                <div className="content">
                    <div>
                        <p>基本设备信息:</p>
                        <Form
                            {...layout}
                            form={Jbform}
                            name="control-hooks"
                            // onFinish={onFinish}
                        >
                            <Form.Item
                                name="ddetName"
                                label="设备名称"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Input />
                            </Form.Item>
                            <Form.Item
                                name="ddetNumber"
                                label="设备编号"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Input />
                            </Form.Item>
                            <Form.Item
                                name="ddetType"
                                label="设备类型"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Select placeholder="" allowClear>
                                    <Option value="	ISS20200890">
                                        ISS20200890
                                    </Option>
                                    <Option value="	ISS20200891">
                                        ISS20200891
                                    </Option>
                                    <Option value="	ISS20200892">
                                        ISS20200892
                                    </Option>
                                </Select>
                            </Form.Item>
                            <Form.Item
                                name="ddetFactorydate"
                                label="运行时间"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <DatePicker className="width_centent" />
                            </Form.Item>
                            <Form.Item
                                name="dinfState"
                                label="运行状态"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Select placeholder="" allowClear>
                                    <Option value="正常">正常</Option>
                                    <Option value="异常">异常</Option>
                                    <Option value="警告">警告</Option>
                                </Select>
                            </Form.Item>
                            <Form.Item
                                name="adminName"
                                label="跟进人"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Select placeholder="1" allowClear>
                                    <Option value="1">1</Option>
                                    <Option value="2">2</Option>
                                    {/* <Option value="警告">警告</Option> */}
                                </Select>
                            </Form.Item>
                            <Form.Item
                                name="adminPhone"
                                label="联系方式"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Input />
                            </Form.Item>
                            <Form.Item
                                name="style"
                                label="类型"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Input />
                            </Form.Item>
                        </Form>
                    </div>
                    <div>
                        <p>设备详细信息:</p>
                        <div>
                            <div>
                                <Form
                                    {...layout}
                                    form={Grform}
                                    name="control-hooks"
                                    // onFinish={onFinish}
                                >
                                    <Form.Item
                                        name="banben"
                                        label="产品版本："
                                        rules={[
                                            {
                                                required: true,
                                            },
                                        ]}
                                    >
                                        <Input />
                                    </Form.Item>
                                    <Form.Item
                                        name="factory"
                                        label="设备厂家："
                                        rules={[
                                            {
                                                required: true,
                                            },
                                        ]}
                                    >
                                        <Input />
                                    </Form.Item>
                                    <Form.Item
                                        name="dinfLocation"
                                        label="安装位置"
                                        // rules={[
                                        //     {
                                        //         required: true,
                                        //     },
                                        // ]}
                                    >
                                        <Input />
                                    </Form.Item>
                                    <Form.Item>
                                        <div className="ditu"></div>
                                    </Form.Item>
                                </Form>
                            </div>
                            <div>
                                <Form
                                    {...layout}
                                    form={bbform}
                                    name="control-hooks"
                                    // onFinish={onFinish}
                                >
                                    <Form.Item
                                        label="现场照片"
                                        name="dinfLivephoto"
                                        // rules={[{ required: true }]}
                                    >
                                        <Form.Item
                                            name="dragger"
                                            valuePropName="fileList"
                                            getValueFromEvent={normFile}
                                            noStyle
                                        >
                                            <Upload.Dragger
                                                name="files"
                                                action="/upload.do"
                                            >
                                                <p className="ant-upload-drag-icon">
                                                    <InboxOutlined />
                                                </p>
                                            </Upload.Dragger>
                                        </Form.Item>
                                    </Form.Item>
                                    <Form.Item
                                        label="设备照片"
                                        name="dinfDevicephoto"
                                        // rules={[{ required: true }]}
                                    >
                                        <Form.Item
                                            name="dragger"
                                            valuePropName="fileList"
                                            getValueFromEvent={normFile}
                                            noStyle
                                        >
                                            <Upload.Dragger
                                                name="files"
                                                action="/upload.do"
                                            >
                                                <p className="ant-upload-drag-icon">
                                                    <InboxOutlined />
                                                </p>
                                            </Upload.Dragger>
                                        </Form.Item>
                                    </Form.Item>

                                    <Form.Item {...tailLayout}>
                                        <div className="btntss">
                                            <Button
                                                type="primary"
                                                htmlType="submit"
                                                onClick={AddData}
                                            >
                                                保存
                                            </Button>
                                            <Button onClick={quxiao}>
                                                取消
                                            </Button>
                                        </div>
                                    </Form.Item>
                                </Form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    );
};
export default AddIntelligent_lighting;
